<?php

trait CoreTraitSingleton
{
    private static ?array $instances = [];

    final public static function getSingle($key, $call, ...$args)
    {
        if (!isset(self::$instances[$key])) {
            self::$instances[$key] = false;
            if (is_callable($call)) {
                self::$instances[$key] = call_user_func($call, ...$args);
            }
        }

        return self::$instances[$key];
    }

    final public static function removeSingle($key)
    {
        unset(self::$instances[$key]);
    }
}